package yunhe.servlet;

import yunhe.biz.impl.StockMgrBizImpl;
import yunhe.entity.EmpMsg;
import yunhe.entity.Product;
import yunhe.entity.StockTransfer;
import yunhe.entity.Storage;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Date;

/**
 * Created by lzh on 2017/6/19.
 */
@WebServlet(name = "StockTransferServlet", urlPatterns = "/StockTransferServlet")
public class StockTransferServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String oldSto = request.getParameter("oldSto");
        String newSto = request.getParameter("newSto");
        String opr = request.getParameter("opr");
        String proBarCode = request.getParameter("proBarCode");
        String traNum = request.getParameter("traNum");
        String res = request.getParameter("res");

        StockTransfer st = new StockTransfer();
        {
            Storage s = new Storage();
            s.setStoId(oldSto);
            st.setOriginStorage(s);
            s.setStoId(newSto);
            st.setGoalStorage(s);
        }

        {
            EmpMsg e = new EmpMsg();
            e.setWorkId(opr);
            st.setEmpMsg(e);
        }
        {
            Product p=new Product();
            p.setProBarCode(proBarCode);
            st.setProduct(p);
        }

        st.setStockTransgerQuantity(Integer.parseInt(traNum));
        st.setTransReason(res);
        st.setTransDate(new Date(new java.util.Date().getTime()));

        int re=new StockMgrBizImpl().transInv(st);
        if(re>0){
            response.getWriter().print("true");
        }
        else{
            response.getWriter().print("false");
        }

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
